<?php 
    require 'page-check.php';
	include 'config.php';
	
	// 1、连接MySQL服务
	$link = @mysql_connect('localhost', 'root', 'root') or die('连接MySQL服务器失败：' . mysql_error());
		
	// 2、选择数据库
	@mysql_select_db('news') or die('选择数据库失败：' . mysql_error());
		
	// 3、设置编码
	mysql_set_charset('utf8');
		
	// 4、执行SQL语句
	$result = mysql_query("select u.username, n.id 'newsid', n.title, n.content, n.publish_date, n.views from user u, news n where u.id = n.user_id order by n.id desc");
	$data =array();
	while ($row = mysql_fetch_array($result)) {
		$data[] =$row;
	}
	// 5、关闭MySQL服务
	mysql_close($link);
	
	//echo "<pre>";
	//print_r($data);
	$username = $_SESSION['username'];
	
	$Smarty->assign("username",$username);
	$Smarty->assign("Datalist",$data);
	$Smarty->display("main.html"); //输出模板